﻿using System.Linq;
using Core.AbstractEntities;
using System.Runtime.Serialization;

namespace Stack.Entities
{
    /// <summary>
    /// Collection of items stored in memory
    /// </summary>
    [DataContract]
    public class HpMemory : HpCollection
    {
        /// <summary>
        /// Add element to the list
        /// </summary>
        /// <param name="element">element to add</param>
        /// <param name="nomVar">nom of the var</param>
        public void AddElement(HpElement element, string nomVar)
        {
            element.Stored = true;
            element.NomVar = nomVar;
            Add(element);
        }
        /// <summary>
        /// Add element to the list
        /// </summary>
        /// <param name="element">element to add</param>
        public override void AddElement(Core.AbstractEntities.HpElement element)
        {
            this.Add(element);
        }
        /// <summary>
        /// Send the element
        /// </summary>
        /// <param name="index">Position of the element in the list</param>
        /// <returns>An element</returns>
        public HpElement Get(string nomVar)
        {
            return this.Single(r => r.NomVar == nomVar);
        }
        /// <summary>
        /// Delete the element of the list
        /// </summary>
        /// <param name="nomVar">nom of the var</param>
        public void Delete(string nomVar)
        {
            HpElement elementTodelete = Get(nomVar);
            this.Remove(elementTodelete);
        }
    }
}
